﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;

namespace RiskMan.Config
{
    /// <summary>
    /// Interaction logic for CalendarWindow.xaml
    /// </summary>
    public partial class CalendarWindow : Window
    {
        public CalendarWindow()
        {
            InitializeComponent();
            var initialDate = new DateTime(2014, 01, 01);
            List<string> list = new List<string>();

            if (MainWindow.StaticLevel._dataProvider.CalendarItemList.Count==0 )
            while (initialDate < new DateTime(2014, 12, 31))
            {
                CalendarItemLevel item = new CalendarItemLevel();
                item.DateOfYear = initialDate.Date.ToShortDateString();
                item.DayOfWeek = initialDate.DayOfWeek.ToString();
                item.ShablonTimeList = list;
                if (item.DayOfWeek == "Воскресенье" || item.DayOfWeek == "Суббота")
                    item.ShablonTime = "Выходной день";
                else
                {
                    item.ShablonTime = "Рабочий день";
                }
                
                initialDate = initialDate.AddDays(1);
                MainWindow.StaticLevel._dataProvider.CalendarItemList.Add(item);
            }

            try
            {
                dtgdCalendar.ItemsSource = MainWindow.StaticLevel._dataProvider.CalendarItemList;
            }
            catch 
            {
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            TamplateTimeWorking time = new TamplateTimeWorking();
            time.ShowDialog();
        }
    }


    /// <summary>
    /// Список дней и времени работы биржы
    /// </summary>
    public class CalendarItemLevel : INotifyPropertyChanged
    {
        //Базовые настройки
        private string _dateOfYear;
        private string _dayOfWeek;
        private List<string> _shablonTimeList;
        private string _shablonTime;

        /// <summary>
        /// Дата 
        /// </summary>
        public string DateOfYear
        {
            get { return _dateOfYear; }
            set
            {
                if (_dateOfYear != value)
                {
                    _dateOfYear = value;
                    RaisePropertyChanged("DateOfYear");
                }
            }
        }

        /// <summary>
        /// день недели
        /// </summary>
        public string DayOfWeek
        {
            get { return _dayOfWeek; }
            set
            {
                if (_dayOfWeek != value)
                {
                    switch (value)
                    {
                        case "Sunday":
                            value = "Воскресенье";
                            break;
                        case "Monday":
                            value = "Понедельник";
                            break;
                        case "Tuesday":
                            value = "Вторник";
                            break;
                        case "Wednesday":
                            value = "Среда";
                            break;
                        case "Thursday":
                            value = "Четверг";
                            break;
                        case "Friday":
                            value = "Пятница";
                            break;
                        case "Saturday":
                            value = "Суббота";
                            break;
                    }
                    _dayOfWeek = value;
                    RaisePropertyChanged("DayOfWeek");
                }
            }
        }
        /// <summary>
        /// шаблоны времени
        /// </summary>
        public List<string> ShablonTimeList
        {
            get { return _shablonTimeList; }
            set
            {
                if (_shablonTimeList != value)
                {
                    _shablonTimeList = value;
                    RaisePropertyChanged("ShablonTimeList");
                }
            }
        }

        /// <summary>
        /// выбранный шаблон времени
        /// </summary>
        public string ShablonTime
        {
            get { return _shablonTime; }
            set
            {
                if (_shablonTime != value)
                {
                    _shablonTime = value;
                    RaisePropertyChanged("ShablonTime");
                }
            }
        }

        #region event PropertyChangedEventHandler

        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion
    }

    public class StatusList : List<string>
    {


        public StatusList()
        {
            foreach (var item in MainWindow.StaticLevel._dataProvider.TamplateTimeWorkingList)
            {
                this.Add(item.Name);
            }
            //this.Add("dsf");
            //this.Add("Closed");
            //this.Add("In Progress");
            //this.Add("Open");
            //this.Add("Resolved");
        }
    }
}
